<!-- 页面 -->
<template>
  <div class="q2">
    <div class="q1">
      <div class="w1">
      <img src="@/assets/logo.png" alt="">
    </div>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="姓名" prop="username">
    <el-input type="username" v-model="ruleForm.username" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="add()">登录</el-button>
  <el-button >重置</el-button>
  </el-form-item>
</el-form>
    </div>
  </div>
</template>
<!--vue -->
<script>
export default {
data() {
return {
//声明的属性
ruleForm:{
    username:"",
    password:"",
},
rules:{
  username:[
      {required:true,message:'请输入用户名',trigger:'blur'},
      {min:3,max:6,message:'请输入3-6位字符',trigger:'blur'}
  ],
  password:[
      {required:true,message:'请输入密码',trigger:'blur'},
      {min:3,max:6,message:'请输入3-6位数字',trigger:'blur'}
  ],
}
 
}
},
//生命周期函数
mounted() {
},
//调用方法
methods: {
    add(){
        this.$refs.ruleForm.validate(async valid=>{
            if(valid){
             const{data}=await this.axios.post('/login',this.ruleForm)
             if(data.meta.status===200){
                sessionStorage.token=data.data.token
                this.$router.push('/home')
                this.$message.success(data.meta.msg)
             }else{
                 this.$message.error(data.meta.msg)
             }
            }else{
                console.log('效验不符合')
            }
        })
    }
},
//监听器
watch: {},
// 计算属性
computed: {},
//过滤器
filters: {},
//自定义指令
directives: {},
}
</script>
<!-- css样式 -->
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
.q2 {
  width: 100%;
  height: 1000px;
  background-color:  !important;
}
.q1 {
  width: 400px;
  height: 260px;
  background-color: white;
  position: absolute;
  margin-top: 205px;
  margin-left: 203px;
  /* text-align: center; */
  /* align-items: center; */
}
.q1 .el-form{
  /* text-align: center; */
  /* align-items: center; */
  margin-top: -55px;

}
.el-form {
  margin-right: 80px;
}
/* /.inp {
  margin: 20px 0;
}
.q1 .q3 {
  margin-top: 30px;
} */
img {
  width: 100px;
  height: 100px;
} 
.w1 {
  width: 150px;
  height: 150px;
  background-color:white;
  border-radius: 50%;
  text-align: center;
  align-items: center;
  margin-left: 130px;
  margin-top: -60px;
}
</style>